<?php
	//Lấy danh sách các menu từ các bảng tbl_menu và tbl_submenu đưa ra danh sách menu
	include_once "classes/menu_bs.php";
	include_once "classes/submenu_bs.php";
	$menu = new menu_bs();
	$menu->SetTrangThai(1);
	$data_menu = $menu->LayDanhSach();
	
	$submenu = new submenu_bs();
?>

<div id="Menu">
	<div id="MainMenu">
		<ul id="nav">
			<?php
				for($i = 0; $i < count($data_menu); $i++)
				{
					$loaimenu = $data_menu[$i]['MaLoaiMenu'];
					$link_tmp = "";
					switch($loaimenu)
					{
						case 1:
							$link_tmp = "index.php?action=baiviet_danhsach&chude=" . $data_menu[$i]['MaChuDe'];
							break;
						case 2:
							$link_tmp = $data_menu[$i]['Link'];
							break;
						case 3:
							$link_tmp = $data_menu[$i]['Link'];
							break;
						case 4:
							$link_tmp = $data_menu[$i]['Link'];
							break;
						default:
							$link_tmp = $data_menu[$i]['Link'];
							break;
					}
					if($data_menu[$i]['Current'] == 1)
						echo '<li class="current"><a href="' . $link_tmp . '">' . $data_menu[$i]['TenMenu'] . '</a>';
					else
						echo '<li><a href="' . $link_tmp . '">' . $data_menu[$i]['TenMenu'] . '</a>';
					
					$submenu->SetMaMenu($data_menu[$i]['MaMenu']);
					$submenu->SetTrangThai(1);
					$data_submenu = $submenu->LayDanhSach();
					if($data_submenu != null)
					{
						echo '<ul>';
							for($j = 0; $j < count($data_submenu); $j++)
							{
								if($data_submenu[$j]['MaLoaiMenu'] == 1)
									$link_sub_tmp = "index.php?action=baiviet_danhsach&chude=." . $data_submenu[$j]['MaChuyenMuc'];
								else
									$link_sub_tmp = $data_submenu[$j]['Link'];
								
								echo '<li><a href="' . $link_sub_tmp . '">' . $data_submenu[$j]['TenSubMenu'] . '</a></li>';
							}
						echo '</ul>';
					}
						
					echo '</li>';
				}
			?>
		</ul>
	</div>
</div>